<?php 
	include_once("testingsocket.php");
	session_start();
	
	if($_GET['gowhere']){
		//echo $_GET['gowhere'];
		$_SESSION["remDir"] = $_GET['gowhere'];
	}
	
	//Marian .... handling the get option of files from server
	if ($_GET['doit'] == "saveit") {
		$len = strlen($_GET['files']);
		$filesList = substr($_GET['files'], 0 , len-1);
		$files = explode(":", $filesList);
		//echo $_SESSION['localDir'];
		//echo "</br>";
		//print_r($files);
		
		foreach ($files as $file) {
			//Send a GET request to the client process
		    //get(server path, client path)
			//echo $file;
			//echo "</br>";					
			if($_SESSION['localDir']){			
				get($file,$_SESSION['localDir']."/".substr(strrchr($file, "/"), 1));
			}
			else 
				echo "<SCRIPT LANGUAGE='javascript'>showErrorMessage(\"You must select a local file first.\");</SCRIPT>";
		}
	}	
?>

</br>
<table border="0" cellspacing="0" cellpadding="4" align="left" style="background-color:#FE9A2E;">
	  

<tr>
<table cellpadding="0" border="1" cellspacing="0" width="30%">
	<thead>
	  <thead>
	  <tr class="graylabel">
		<td width = "2">&nbsp;</td>
		<td width = "2">Select</td>
		<td><a href="#" onclick="return sortTable('TBOServerBrowse',2);" class="sortlink" title="Click to sort">Name</a></td>
		<td><a href="#" onclick="return sortTable('TBOServerBrowse',3);" class="sortlink" title="Click to sort">File Type</a></td>
	 </tr>
	</thead>
	  <tbody id="TBOServerBrowse"> 
	<? 
	
	//Request a LIST for the list of files from the server ... 
	
	$serverPath = $_SESSION["remDir"];	
	$filesList = lis($serverPath);
	if(!empty($filesList)){	
		foreach($filesList as $file) {
			echo "<tr><td><img src=\"img/page.gif\" style=\"width:18px;height:18px; border:0px none;\" /></td>
			<td><input type=\"checkbox\" path=\"".$_SESSION["remDir"]."/".$file->fileName."\" name=\"selectedFiles[".$_SESSION["remDir"]."/".$file->fileName."]\" value=\"1\"></td>
			<td nowrap=\"nowrap\">".$file->fileName."</td>";
			
			if($file->fileType === "f")
				echo "<td nowrap=\"nowrap\">FILE</td></tr>";
			else 		
				echo "<td nowrap=\"nowrap\">DIR</td></tr>";
		}	
	}
	echo "</tbody></table> "; ?>
</tr>
</table>
